/**
 * 
 */
package edu.gtcfla.km.platform.service.impl;

import java.util.LinkedHashSet;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.vsg.biz.account.User;
import org.vsg.biz.account.repositories.UserRepo;

import edu.gtcfla.km.platform.service.SystemUserManager;
import edu.gtcfla.km.platform.vo.SystemUserVO;
import edu.gtcfla.km.security.api.Account;
import edu.gtcfla.km.security.api.SubjectManager;

/**
 * @author vison
 *
 */
public class SystemUserManagerI implements SystemUserManager {

	@Autowired(required=false)
	private UserRepo<User,String> userRepo;

	@Autowired(required = false)
	private SubjectManager subjectManager;		
	
	/* (non-Javadoc)
	 * @see org.vsg.crm.platform.service.UserAndStaffManager#findAllAvaiableStaffUser(java.lang.String)
	 */
	@Override
	public Set<SystemUserVO> findAllAvaiableSystemUser(String currentUserId) {
		
		Account account = null;
		if ( currentUserId == null) {
			currentUserId = subjectManager.getCurrentAccountId();
			account = subjectManager.getCurrentAccount();
		}
		
		Set<SystemUserVO> results = new LinkedHashSet<SystemUserVO>();
		
		// --- all available user ---
		for (User one : userRepo.findAll() )  {
			
			SystemUserVO sysUser = new SystemUserVO();
			sysUser.setId( one.getId() );
			sysUser.setName( one.getName() );
			sysUser.setCode( one.getCode() );
			
			if (currentUserId != null && currentUserId.equals( one.getId() ) ) {
				sysUser.setCurrentUser(true);
			}
			
			results.add( sysUser );					
			
		}
		
		return results;
	}

	@Override
	public Set<SystemUserVO> findAllStaffUserWithSubordinates(
			String currentUserId) {
		
		Account account = null;
		if ( currentUserId == null) {
			currentUserId = subjectManager.getCurrentAccountId();
			account = subjectManager.getCurrentAccount();
		}
		

		
		return null;
	}
	
	
	

}
